package com.application.race.manage;

import org.apache.mina.core.buffer.IoBuffer;

import com.application.actor.pojo.Actor;
import com.application.room.pojo.Room;

public class RaceManage
{


    private static RaceroomManage roomMng;
 
	static final int MAX_USER_NUMBER=400;
 
    public static void init(){
    	roomMng = new RaceroomManage();
		roomMng.start();
    }
    public static boolean applyCreateRacingRoom(Room room){

    	boolean c=roomMng.createRoom(room);
    	if(c){
//    		service.invoke("roomCraeated",new Object[0]);
    		System.out.println("create room "+room.roomId);
    	    return true;
    	}
    	else{
//    		service.invoke("roomCraeateFailed",new Object[0]);
    		System.out.println("create room "+room.roomId+"   error!!!");
    		return false;
    	}
    	//getCurrentConn().close();
    }
    public static void actorOnline(Actor a){
    	for(RacingRoom r:roomMng.rooms.values()){
    		if(r.players.containsKey(a.getId())){
    			r.actorApplyReturnRoom(a);
    			return;
    		}
    	}
    	 
    }
  
    public static void raceAction(Actor a,IoBuffer bf){
    	
    	RacingRoom r=roomMng.rooms.get(a.roomId);
    	if(r==null)return;
    	r.addTask(a, bf);
    }
	
}
